package com.itheima.web;

import com.itheima.pojo.Student;
import com.itheima.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Xiao
 * @date 2021/9/1
 */
@WebServlet("/selectBySnameServlet")
public class SelectByISnameServlet extends HttpServlet {
    private static StudentService studentService =new StudentService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String sname = request.getParameter("sname");
        Student student = studentService.selectBySname(sname);
        request.setAttribute("stu", student);
        request.getRequestDispatcher("/add.jsp").forward(request,response); //转发
        //request.getRequestDispatcher("/update.jsp").forward(request,response); //转发
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
